﻿using System;

namespace Framework
{
    public class Model : IModel
    {
        private IEventDispatcher _eventDispatcher;
        private IModuleEventDispatcher _moduleEventDispatcher;

        public virtual void Init()
        {
        }

        public virtual void Connect(IEventDispatcher eventDispatcher, IModuleEventDispatcher moduleEventDispatcher)
        {
            _eventDispatcher = eventDispatcher;
            _moduleEventDispatcher = moduleEventDispatcher;

            Init();
        }

        public virtual void Dispose()
        {
        }

        #region 处理事件

        public void AddModuleListener<T>(string eventName, Action<T> handler)
        {
            _moduleEventDispatcher.AddModuleListener(eventName, handler);
        }

        public void AddModuleListener(string eventName, Action handler)
        {
            _moduleEventDispatcher.AddModuleListener(eventName, handler);
        }

        public void AddModuleListener<T, U>(string eventName, Action<T, U> handler)
        {
            _moduleEventDispatcher.AddModuleListener(eventName, handler);
        }

        public void AddModuleListener<T, U, V>(string eventName, Action<T, U, V> handler)
        {
            _moduleEventDispatcher.AddModuleListener(eventName, handler);
        }

        public void AddModuleListener<T, U, V, W>(string eventName, Action<T, U, V, W> handler)
        {
            _moduleEventDispatcher.AddModuleListener(eventName, handler);
        }

        public void CleanupModuleEvents()
        {
            _moduleEventDispatcher.CleanupModuleEvents();
        }

        public void RemoveModuleEvents(string eventName)
        {
            _moduleEventDispatcher.RemoveModuleEvents(eventName);
        }

        public void RemoveModuleListener(string eventName, Action handler)
        {
            _moduleEventDispatcher.RemoveModuleListener(eventName, handler);
        }

        public void RemoveModuleListener<T>(string eventName, Action<T> handler)
        {
            _moduleEventDispatcher.RemoveModuleListener(eventName, handler);
        }

        public void RemoveModuleListener<T, U>(string eventName, Action<T, U> handler)
        {
            _moduleEventDispatcher.RemoveModuleListener(eventName, handler);
        }

        public void RemoveModuleListener<T, U, V>(string eventName, Action<T, U, V> handler)
        {
            _moduleEventDispatcher.RemoveModuleListener(eventName, handler);
        }

        public void RemoveModuleListener<T, U, V, W>(string eventName, Action<T, U, V, W> handler)
        {
            _moduleEventDispatcher.RemoveModuleListener(eventName, handler);
        }

        public void AddListener<T>(string eventName, Action<T> handler)
        {
            _eventDispatcher.AddListener(eventName, handler);
        }

        public void AddListener(string eventName, Action handler)
        {
            _eventDispatcher.AddListener(eventName, handler);
        }

        public void AddListener<T, U>(string eventName, Action<T, U> handler)
        {
            _eventDispatcher.AddListener(eventName, handler);
        }

        public void AddListener<T, U, V>(string eventName, Action<T, U, V> handler)
        {
            _eventDispatcher.AddListener(eventName, handler);
        }

        public void AddListener<T, U, V, W>(string eventName, Action<T, U, V, W> handler)
        {
            _eventDispatcher.AddListener(eventName, handler);
        }

        public void Cleanup()
        {
            _eventDispatcher.Cleanup();
        }

        public void RemoveEvents(string eventName)
        {
            _eventDispatcher.RemoveEvents(eventName);
        }

        public void RemoveListener(string eventName, Action handler)
        {
            _eventDispatcher.RemoveListener(eventName, handler);
        }

        public void RemoveListener<T>(string eventName, Action<T> handler)
        {
            _eventDispatcher.RemoveListener(eventName, handler);
        }

        public void RemoveListener<T, U>(string eventName, Action<T, U> handler)
        {
            _eventDispatcher.RemoveListener(eventName, handler);
        }

        public void RemoveListener<T, U, V>(string eventName, Action<T, U, V> handler)
        {
            _eventDispatcher.RemoveListener(eventName, handler);
        }

        public void RemoveListener<T, U, V, W>(string eventName, Action<T, U, V, W> handler)
        {
            _eventDispatcher.RemoveListener(eventName, handler);
        }

        #endregion
    }
}